package com.github.shuaidd.service.runtime;

import lombok.RequiredArgsConstructor;
import org.activiti.engine.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class LwfProcessInstanceService {

    private final LwfRelatedContentService relatedContentService;
    private final LwfCommentService commentService;
    private final HistoryService historyService;
    
    @Transactional
    public void deleteProcessInstance(String processInstanceId) {
        // Delete all content related to the process instance
        relatedContentService.deleteContentForProcessInstance(processInstanceId);
        
        // Delete all comments on tasks and process instances
        commentService.deleteAllCommentsForProcessInstance(processInstanceId);
        
        // Finally, delete all history for this instance in the engine
        historyService.deleteHistoricProcessInstance(processInstanceId);
    }
}
